home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12319 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
  4. Subject: Re: How can I check whether I file exists in a multi-user environment?
  5. Date: 30 Mar 1996 10:21:01 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4jjn1d$clu@solutions.solon.com>
  8. References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <Dp1oM8.Cns@iquest.net>, Doug Miller <dlmiller@iquest.net> wrote:
  12. >        * * * * C A U T I O N * * * *
  13. >Although this will work in many implementations, to the best of my knowledge
  14. >it is *NOT* ANSI C.
  15.  
  16. Then why post it to comp.lang.c?  Why not just email it to the user, along
  17. with a pointer to the correct newsgroup?  (Which is even in the newsgroups
  18. list...)
  19.  
  20. >#include <io.h>
  21. >int file_exists (char *filename) {
  22. >    return (access(filename, 0) == 0);
  23. >} /* returns -1 if file exists, 0 if it does not */
  24.  
  25. The reason this is a poor solution is that it doesn't test for existance,
  26. it tests for accessibility.  In modern environments, such as NT or Unix,
  27. it is quite possible for a file to exist but be inaccessible.  There is
  28. no real way in such environments to test for existance; you aren't allowed to
  29. know whether someone else has a file they don't want you to know about.
  30.  
  31. Also, on any POSIX-like system, access is in <unistd.h>.  This may be useful
  32. to someone planning to work with multiple systems, or in any event NT, which
  33. has some POSIX to it.
  34.  
  35. -s
  36. -- 
  37. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  38. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  39. FUCK the communications decency act.  Goddamned government.  [literally.]
  40. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  41.